package com.byxy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.byxy.service.ForumService;

@Controller
public class ForumController {
	@Autowired
	private ForumService forumService;

	@RequestMapping("toForumManagePage.do")
	public String toForumManager(Model model) {
		model.addAttribute("forums", forumService.findAll());
		return "forumManage";
	}

	@GetMapping("toAddForumPage.do")
	public String toAddForumPage() {
		return "addForum";
	}

	@RequestMapping("addForum.do")
	public String addForum(@RequestParam("forum_name") String forumName) {
		forumService.add(forumName);
		return "redirect:toForumManagePage.do";
	}

	@RequestMapping("toModifyForumPage.do")
	public String toModifyForumPage(Model model, @RequestParam("forumId") Integer forumId) {
		model.addAttribute("forum", forumService.get(forumId));
		return "modifyForum";
	}

	@RequestMapping("modifyForumInfo.do")
	public String modifyForumInfo(@RequestParam("forum_name") Integer forumName, @RequestParam("forum_id") Integer forumId) {
		forumService.update(forumName,forumId);
		return "redirect:toForumManagePage.do";
	}

	@RequestMapping("disEnableForum.do")
	public String disEnableForum(@RequestParam("forumId") Integer forumId) {
		forumService.delete(forumId);
		return "redirect:toForumManagePage.do";
	}

}
